package com.baolai.mapper;

import com.baolai.dto.RecordGoods;
import com.baolai.entity.GoodsRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GoodsRecordMapper extends BaseMapper<GoodsRecord> {

    @Select("select top ${size} * from (" +
            "select *,row_number() over(order by record_date desc) row from (" +
            "select goods_record.id as id,goods_record.type as type,goods_record.goods_id as goods_id,goods.name as goods_name," +
            "goods.type as goodsType,goods.valuation as goodsValue,goods_record.site as site,goods_record.number as number," +
            "goods_record.account as account,goods_record.name as name,goods_record.record_date as record_date " +
            "from goods_record " +
            "left join goods on goods_record.goods_id = goods.id) t1) t2 " +
            "where t2.row > ${current}")
    List<RecordGoods> listRecordGoods(Integer current,Integer size);

    @Select("select top ${size} * from (" +
            "select *,row_number() over(order by record_date desc) row from (" +
            "select goods_record.id as id,goods_record.type as type,goods_record.goods_id as goods_id,goods.name as goods_name," +
            "goods.type as goodsType,goods.valuation as goodsValue,goods_record.site as site,goods_record.number as number," +
            "goods_record.account as account,goods_record.name as name,goods_record.record_date as record_date " +
            "from goods_record " +
            "left join goods on goods_record.goods_id = goods.id " +
            "where goods_record.goods_id = '${goodsId}' and goods_record.record_date <= '${end}' and goods_record.record_date >= '${begin}') t1) t2 " +
            "where t2.row > ${current}")
    List<RecordGoods> queryRecordGoodsByGoodsId(String goodsId,String begin,String end,Integer current,Integer size);

    @Select("select top ${size} * from (" +
            "select *,row_number() over(order by record_date desc) row from (" +
            "select goods_record.id as id,goods_record.type as type,goods_record.goods_id as goods_id,goods.name as goods_name," +
            "goods.type as goodsType,goods.valuation as goodsValue,goods_record.site as site,goods_record.number as number," +
            "goods_record.account as account,goods_record.name as name,goods_record.record_date as record_date " +
            "from goods_record " +
            "left join goods on (goods_record.goods_id = goods.id) " +
            "where goods_record.record_date <= '${end}' and goods_record.record_date >= '${begin}') t1) t2 " +
            "where t2.row > ${current}")
    List<RecordGoods> queryRecordGoods(String begin,String end,Integer current,Integer size);
}
